// Author: Bjorn Schobben

#include "Color.h"

Color::Color(int newColor): color(newColor)
{
}

Color::Color(const Color& rhs): color(rhs.color)
{
}

Color::~Color()
{
}

//Return the color value (integer)
int Color::GetColorValue() const
{
	return color;
}

//Set the color (Color)
void Color::SetColor(const Color& newColor)
{
	SetColorValue(newColor.color);
}

//Set the color value (integer)
void Color::SetColorValue(int newColor)
{
	color = newColor;
}

//Return the R-part of the RGB-code
int Color::GetRed() const
{
	return (color >> 16) & 0xFF;
}

//Return the G-part of the RGB-code
int Color::GetGreen() const
{
	return (color >> 8) & 0xFF;
}

//Return the B-part of the RGB-code
int Color::GetBlue() const
{
	return (color >> 0) & 0xFF;
}

//Set the R-part of the RGB-code 
void Color::SetRed(int red)
{
	SetColorValue((color & 0x00FFFF) | ((red & 0xFF)<<16));
}

//Set the G-part of the RGB-code
void Color::SetGreen(int green)
{
	SetColorValue((color & 0xFF00FF) | ((green & 0xFF)<<8));
}

//Set the B-part of the RGB-code
void Color::SetBlue(int blue)
{
	SetColorValue((color & 0xFFFF00) | ((blue & 0xFF)<<0));
}

//Overloaded operator = for colors
Color& Color::operator=(const Color& rhs)
{
	if (this != &rhs)
	{
		SetColorValue(rhs.color);
	}

	return *this;
}

//Erase the current color value
void Color::EraseColor()
{
	SetColorValue(NOCOLOR);
}

//Check if the a color is set
bool Color::IsColor() const
{
	return color != NOCOLOR;
}

//Overloaded operator == for colors
bool Color::operator==(const Color& rhs) const
{
	bool result = false;

	if (color == rhs.color)
	{
		result = true;
	}

	return result;
}

bool Color::operator!=(const Color& rhs) const
{
	return !operator==(rhs);
}